<?php

namespace App\Http\Controllers;

use App\Services\IdEncryptService;
use Illuminate\Http\Request;
use TestingDeveloperService;
use TestingConfig;
use UserRecordService;
class TestController extends Controller
{
    //
    public function config(){
        $settings = config('testing');
        return apiJson(0,$settings,'success');
    }


    public function gotoConfig(){
        redirect(route('testing.config1'));
    }

    public function encodeId(Request $request){
        $id = $request->input("id");
        if(!$id){
            return apiFailed(null,"id invalid");
        }
        return apiSuccess(IdEncryptService::encryption($id,'encode'));
    }


    public function testSyncUserOrderInfo(Request $request){
        $thirdpartyName = $request->input("thirdparty_name");
        if(!$thirdpartyName){
            return apiFailed(null,"thirdpartyName invalid");
        }
        $uid = $request->input("uid");
        if(!$uid){
            return apiFailed(null,"uid invalid");
        }
        $tid = $request->input("tid");
        if(!$tid){
            return apiFailed(null,"tid invalid");
        }
        if(!$developer = TestingDeveloperService::getByAbbreviation($thirdpartyName)){
            return apiFailed(null,"thirdparty_name invalid");
        }
        $appid = $developer['appid'];
        //判断是否为减脂openapi的合作伙伴，从而确定订单编号和营养师编号
        $jzOpenApiPartners = json_decode(TestingConfig::getValue('jz.openapi.partners'),true);
        if(in_array($appid,$jzOpenApiPartners)){
            $orderData = UserRecordService::syncJzOpenApiOrderInfo($appid,$uid,$tid);
            $data['nutritionist_id'] = $orderData['nutritionist_id'];
            $data['order_id'] = $orderData['order_id'];
        }
        return apiSuccess($data);


    }
}
